package com.michael.xx.audiorecoder.encoder;

import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.support.annotation.NonNull;

import java.io.IOException;

/**
 * Created by michael_xu on 2017/8/11.
 */

public abstract class AudioEncoder {
    protected int audioSampleRate = 8000;
    protected int sampleSizeInBits = 64;
    protected int channelCount = 1;
    protected String destinationFile;

    public void init(int audioSampleRate, int sampleSizeInBits, int channelCount) {
        this.audioSampleRate = audioSampleRate;
        this.sampleSizeInBits = sampleSizeInBits;
        this.channelCount = channelCount;
    }

    public String getDestFile() {
        return destinationFile;
    }

    @NonNull
    protected MediaFormat getMediaFormat(String sourceFile) throws IOException {
        MediaExtractor mex = new MediaExtractor();
        mex.setDataSource(sourceFile);
        return mex.getTrackFormat(0);
    }

    public abstract void encodeBuffer(byte[] inputBuffer, int pcmOffset, int readSize, byte[] outputBuffer);

    public abstract void close();
}
